/*
 * Copyright © 2004-2014 chenYuan. All rights reserved.
 * @Website:wwww.jspx.net
 * @Mail:39793751@qq.com
 * @author: chenYuan , 陈原
 * @License: Jspx.net Framework Code is open source (LGPL)，Jspx.net Framework 使用LGPL 开源授权协议发布。
 * @jvm:jdk1.6+  x86/amd64
 *
 */
package com.jspx.txweb.view;

import com.jspx.boot.environment.Environment;
import com.jspx.sioc.annotation.Ref;
import com.jspx.txweb.annotation.HttpMethod;
import com.jspx.txweb.annotation.Safety;
import com.jspx.txweb.annotation.TurnPage;
import com.jspx.txweb.dao.MemberDAO;
import com.jspx.txweb.env.TXWebIoc;
import com.jspx.txweb.support.ActionSupport;
import com.jspx.txweb.table.UserSession;
import com.jspx.utils.StringUtil;

import java.util.List;

/**
 * Created by IntelliJ IDEA.
 * User: chenYuan
 * Date: 2010-7-30
 * Time: 17:49:10
 *com.jspx.txweb.view.UserSessionListView
 */
@HttpMethod(caption="在线用户",location="user/\\w+online")
public class UserSessionListView extends ActionSupport
{
    public UserSessionListView()
    {

    }

    private String find = StringUtil.empty;
    private String term = StringUtil.empty;
    private String sort = StringUtil.empty;
    private int count = 0;
    private int currentPage = 1;
    private boolean load = false;

    private MemberDAO memberDAO;
    @Ref(name = TXWebIoc.memberDAO, namespace = TXWebIoc.userNamespace)
    public void setMemberDAO(MemberDAO memberDAO) {
        this.memberDAO = memberDAO;
    }

    @Safety
    public void setCount(int count)
    {
        this.count = count;
    }

    public int getCount()
    {
        if (count <= 0)
        {
            count = config.getInt(Environment.rowCount, 18);
        }
        return count;
    }

    public boolean isLoad()
    {
        return load;
    }

    public void setLoad(boolean load)
    {
        this.load = load;
    }

    private String turnPage = StringUtil.empty;
    @Safety(request = false)
    @TurnPage(params = "find;sort;term", totalCount = "@totalCount", rows = "@count")
    public void setTurnPage(String turnPage)
    {
        this.turnPage = turnPage;
    }

    public String getTurnPage()
    {
        return turnPage;
    }


    public String getFind()
    {
        return find;
    }

    @Safety
    public void setFind(String find)
    {
        this.find = find;
    }

    public String getTerm()
    {
        return term;
    }

    @Safety
    public void setTerm(String term)
    {
        this.term = term;
    }

    public String getSort()
    {
        return sort;
    }

    @Safety
    public void setSort(String sort)
    {
        this.sort = sort;
    }

    public int getCurrentPage()
    {
        return currentPage;
    }

    @Safety
    public void setCurrentPage(int currentPage)
    {
        this.currentPage = currentPage;
    }

    public List<UserSession> getList() throws Exception
    {
        return memberDAO.getOnlineList(term, sort, getCurrentPage(), getCount(),load);
    }

    public long getTotalCount() throws Exception
    {
        return memberDAO.getOnlineCount(term);
    }
}